package com.twoGroup.boot.service.imp;


import com.twoGroup.boot.controller.AddressController;
import com.twoGroup.boot.mapper.AdminMapper;
import com.twoGroup.boot.pojo.GoodsAndShopAndGoodsTypeAndGoodsBrand;
import com.twoGroup.boot.pojo.Page;
import com.twoGroup.boot.pojo.ShopAndUser;
import com.twoGroup.boot.pojo.User;
import com.twoGroup.boot.service.AdminService;
import com.twoGroup.boot.utils.AdminUtils;
import com.twoGroup.boot.utils.TeleNumUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

@Service
public class AdminServiceImp implements AdminService {
    public static Logger logger = LoggerFactory.getLogger(AdminServiceImp.class);
    /**
     * adminMapper是引用类型。 AdminMapper类型的对象是再Spring的配置文件中创建的对象
     * <p>
     * 引用类型自动注入 @Autowired,@Resource
     */
    @Autowired
    private AdminMapper adminMapper;
    private AdminUtils adminUtils = new AdminUtils();
    private static TeleNumUtils teleNumUtils = new TeleNumUtils();
    //增加用户
    @Override
    public String adminAddUser(String nickname, String sex, int age, String password, String telephone, String email, String address, String idCard, String rName) {
        String msg = getTheInsertUserMessage(nickname,sex,age,password,telephone,email,address,idCard,rName);
        return msg;
    }
    //删除用户
    @Override
    public String adminDeleteUser(int userId) {
        int row=checkUserIdIsPresent(userId);
        if (row==0){return "所删除用户不存在";}
        else{
            Integer rows = adminMapper.adminDeleteUser(userId);return "删除用户成功";}
    }
    //批量删除用户
    @Override
    public int adminDeleteUsers(Integer[] userIds) {
        int rows = 0;
        for (Integer userId : userIds) {
            rows = adminMapper.adminDeleteUser(userId);
        }
        return rows;
    }
    //修改用户信息
    @Override
    @Transactional
    public String adminUpdateUser(int userId, String nickname, String sex,String telephone,  String rName) {
        String msg=getTheUpdateUserMessage(userId,nickname,sex,telephone,rName);
        return msg;
    }
    //查询用户详情
    @Override
    public List<User> adminQueryUser(int userId) {
        List<User> list = adminMapper.adminQueryUser(userId);
        return list;
    }
    //增加商家
    @Override
    public String adminAddShopper(String nickname, String sex, int age, String password, String telephone, String email, String address, String idCard, String rName) {
        String msg = getTheInsertShopperMessage(nickname,sex,age,password,telephone,email,address,idCard,rName);
        return msg;
    }
    //删除商家
    @Override
    public String adminDeleteShopper(int userId) {
        int row=checkUserIdIsPresent(userId);
        if (row==0){return "所删除商家不存在";}
        else{
            Integer rows = adminMapper.adminDeleteUser(userId);return "删除商家成功";}
    }
    //批量删除商家
    @Override
    public int adminDeleteShoppers(Integer[] userIds) {
        int rows = 0;
        for (Integer userId : userIds) {
            rows = adminMapper.adminDeleteShopper(userId);
        }
        return rows;
    }
    //修改商家信息
    @Override
    public String adminUpdateShopper(int userId, String nickname, String sex, int age, String password, String telephone, String email, String address, String idCard, String rName) {
        String msg=getTheUpdateShopperMessage(userId,nickname,sex,age,password,telephone,email,address,idCard,rName);
        return msg;
    }
    //根据id查询商家
    @Override
    public List<User> adminQueryShopper(int userId) {
        List<User> list = adminMapper.adminQueryShopper(userId);
        return list;
    }

//删除商品
    @Override
    public String adminDeleteGoods(int goodsId) {
        int row=checkGoodsIdIsPresent(goodsId);
        if (row==0){return "所删除商品不存在";}
        else{

            Integer rows = adminMapper.adminDeleteGoods(goodsId);return "删除商品成功";}
    }
//批量删除商品
    @Override
    public int adminDeleteMoreGoods(Integer[] goodsIds) {
        int rows = 0;
        for (Integer goodsId : goodsIds) {
            rows = adminMapper.adminDeleteGoods(goodsId);
        }
        return rows;
    }

//    @Override
//    public List<GoodsAndShopAndGoodsTypeAndGoodsBrand> adminQueryGoods(int goodsId) {
//        List<GoodsAndShopAndGoodsTypeAndGoodsBrand> list =adminMapper.adminQueryGoods(goodsId);
//        return list;
//    }


//删除店铺
    @Override
    public String adminDeleteShop(int shopId) {
        int row=checkShopIdIsPresent(shopId);
        if (row==0){return "所删除店铺不存在";}
        else{
            Integer rows = adminMapper.adminDeleteShop(shopId);return "删除店铺成功";}
    }
//批量删除店铺
    @Override
    public int adminDeleteShops(Integer[] shopIds) {
        int rows = 0;
        for (Integer shopId : shopIds) {
            rows = adminMapper.adminDeleteShop(shopId);
        }
        return rows;
    }


//    @Override
//    public List<ShopAndUser> adminQueryShop(int shopId) {
//        List<ShopAndUser> list = adminMapper.adminQueryShop(shopId);
//        return list;
//    }
    //修改操作
    //    申请管理列表
    @Override
    public int agreeUserToBeShopper(int userId) {
        int rows = adminMapper.agreeUserToBeShopper(userId);
        return rows;
    }

    @Override
    public int disagreeUserToBeShopper(int userId) {
        int rows = adminMapper.disagreeUserToBeShopper(userId);
        return rows;
    }

    @Override
    public int agreeGoodsToBePutOnSale(int goodsId) {
        int rows = adminMapper.agreeGoodsToBePutOnSale(goodsId);
        return rows;
    }

    @Override
    public int disagreeGoodsToBePutOnSale(int goodsId) {
        int rows = adminMapper.disagreeGoodsToBePutOnSale(goodsId);
        return rows;
    }


    //模糊查询
    @Override
    public List<User> likeUserByNickName(String nickName) {
        return adminMapper.likeUserByNickName(nickName);
    }

    @Override
    public List<User> likeShopperByNickName(String nickName) {
        return adminMapper.likeShopperByNickName(nickName);
    }

    @Override
    public List<GoodsAndShopAndGoodsTypeAndGoodsBrand> likeGoods(String goodsName) {
        return adminMapper.likeGoods(goodsName);
    }

    @Override
    public List<ShopAndUser> likeShop(String shopName) {
        return adminMapper.likeShop(shopName);
    }

    @Override
    public List<User> likeAllUserToBeShopper(String nickName) {
        return adminMapper.likeAllUserToBeShopper(nickName);
    }

    @Override
    public List<GoodsAndShopAndGoodsTypeAndGoodsBrand> likeAllGoodsToBePutOnSale(String goodsName) {
        return adminMapper.likeAllGoodsToBePutOnSale(goodsName);
    }


    //查询全部信息
    @Override
    public List<User> FindAllUser() {

        return adminMapper.FindAllUser();
    }

    @Override
    public List<User> FindAllShopper() {

        return adminMapper.FindAllShopper();
    }

    @Override
    public List<ShopAndUser> FindAllShop() {

        return adminMapper.FindAllShop();
    }

    @Override
    public List<GoodsAndShopAndGoodsTypeAndGoodsBrand> FindAllGoods() {

        return adminMapper.FindAllGoods();
    }

    //    管理列表
    @Override
    public List<User> FindAllUserToBeShopper() {

        return adminMapper.FindAllUserToBeShopper();
    }

    @Override
    public List<GoodsAndShopAndGoodsTypeAndGoodsBrand> FindAllGoodsToBePutOnSale() {

        return adminMapper.FindAllGoodsToBePutOnSale();
    }

    /**
     * 分页操作
     * @param pageNow
     * @param pageSize
     */

    //查询全部
    @Override
    public Page<User> selectUserByPage(@RequestParam(value = "pageNow", defaultValue = "1") int pageNow, @RequestParam(value = "pageSize", defaultValue = "5") int pageSize) {
        Page<User> page = new Page<User>();
//        得到记录总数
        Integer pageToTalCount = adminMapper.getUserCount();
        page.setPageTotalCount(pageToTalCount);
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        int star = (pageNow - 1) * pageSize;
        page.setStart(star);
        ArrayList<User> list = adminMapper.selectUserByPage(page.getStart(), page.getPageSize());
        page.setList(list);
        return page;
    }
    //模糊查询
    @Override
    public Page<User> likeUserByPage(@RequestParam(value = "pageNow", defaultValue = "1") int pageNow, @RequestParam(value = "pageSize", defaultValue = "5") int pageSize, String nickName) {
        Page<User> page = new Page<User>();
//        得到记录总数
        Integer pageToTalCount = adminMapper.getUserCount();
        page.setPageTotalCount(pageToTalCount);
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        int star = (pageNow - 1) * pageSize;
        page.setStart(star);
        ArrayList<User> list = adminMapper.likeUserByPage(page.getStart(), page.getPageSize(), nickName);
        page.setList(list);
        return page;
    }

    @Override
    public Page<User> selectShopperByPage(int pageNow, int pageSize) {
        Page<User> page = new Page<User>();
//        得到记录总数
        Integer pageToTalCount = adminMapper.getShopperCount();
        page.setPageTotalCount(pageToTalCount);
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        int star = (pageNow - 1) * pageSize;
        page.setStart(star);
        ArrayList<User> list = adminMapper.selectShopperByPage(page.getStart(), page.getPageSize());
        page.setList(list);
        return page;
    }

    @Override
    public Page<User> likeShopperByPage(int pageNow, int pageSize, String nickName) {
        Page<User> page = new Page<User>();
//        得到记录总数
        Integer pageToTalCount = adminMapper.getShopperCount();
        page.setPageTotalCount(pageToTalCount);
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        int star = (pageNow - 1) * pageSize;
        page.setStart(star);
        ArrayList<User> list = adminMapper.likeShopperByPage(page.getStart(), page.getPageSize(), nickName);
        page.setList(list);
        return page;
    }

    @Override
    public Page<GoodsAndShopAndGoodsTypeAndGoodsBrand> selectGoodsByPage(int pageNow, int pageSize) {
        Page<GoodsAndShopAndGoodsTypeAndGoodsBrand> page = new Page<GoodsAndShopAndGoodsTypeAndGoodsBrand>();
//        得到记录总数
        Integer pageToTalCount = adminMapper.getGoodsCount();
        page.setPageTotalCount(pageToTalCount);
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        int star = (pageNow - 1) * pageSize;
        page.setStart(star);
        ArrayList<GoodsAndShopAndGoodsTypeAndGoodsBrand> list = adminMapper.selectGoodsByPage(page.getStart(), page.getPageSize());
        page.setList(list);
        return page;
    }

    @Override
    public Page<GoodsAndShopAndGoodsTypeAndGoodsBrand> likeGoodsByPage(int pageNow, int pageSize, String goodsName) {
        Page<GoodsAndShopAndGoodsTypeAndGoodsBrand> page = new Page<GoodsAndShopAndGoodsTypeAndGoodsBrand>();
//        得到记录总数
        Integer pageToTalCount = adminMapper.getGoodsCount();
        page.setPageTotalCount(pageToTalCount);
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        int star = (pageNow - 1) * pageSize;
        page.setStart(star);
        ArrayList<GoodsAndShopAndGoodsTypeAndGoodsBrand> list = adminMapper.likeGoodsByPage(page.getStart(), page.getPageSize(), goodsName);
        page.setList(list);
        return page;
    }

    @Override
    public Page<ShopAndUser> selectShopByPage(int pageNow, int pageSize) {
        Page<ShopAndUser> page = new Page<ShopAndUser>();
//        得到记录总数
        Integer pageToTalCount = adminMapper.getShopCount();
        page.setPageTotalCount(pageToTalCount);
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        int star = (pageNow - 1) * pageSize;
        page.setStart(star);
        ArrayList<ShopAndUser> list = adminMapper.selectShopByPage(page.getStart(), page.getPageSize());
        page.setList(list);
        return page;
    }

    @Override
    public Page<ShopAndUser> likeShopByPage(int pageNow, int pageSize, String shopName) {
        Page<ShopAndUser> page = new Page<ShopAndUser>();
//        得到记录总数
        Integer pageToTalCount = adminMapper.getShopCount();
        page.setPageTotalCount(pageToTalCount);
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        int star = (pageNow - 1) * pageSize;
        page.setStart(star);
        ArrayList<ShopAndUser> list = adminMapper.likeShopByPage(page.getStart(), page.getPageSize(), shopName);
        page.setList(list);
        return page;
    }

    @Override
    public Page<User> selectUserToBeShopperByPage(int pageNow, int pageSize) {
        Page<User> page = new Page<User>();
//        得到记录总数
        Integer pageToTalCount = adminMapper.getUserToBeShopperCount();
        page.setPageTotalCount(pageToTalCount);
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        int star = (pageNow - 1) * pageSize;
        page.setStart(star);
        ArrayList<User> list = adminMapper.selectUserToBeShopperByPage(page.getStart(), page.getPageSize());
        page.setList(list);
        return page;
    }

    @Override
    public Page<User> likeUserToBeShopperByPage(int pageNow, int pageSize, String nickName) {
        Page<User> page = new Page<User>();
//        得到记录总数
        Integer pageToTalCount = adminMapper.getUserToBeShopperCount();
        page.setPageTotalCount(pageToTalCount);
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        int star = (pageNow - 1) * pageSize;
        page.setStart(star);
        ArrayList<User> list = adminMapper.likeUserToBeShopperByPage(page.getStart(), page.getPageSize(), nickName);
        page.setList(list);
        return page;
    }

    @Override
    public Page<GoodsAndShopAndGoodsTypeAndGoodsBrand> selectGoodsToBePutOnSaleByPage(int pageNow, int pageSize) {
        Page<GoodsAndShopAndGoodsTypeAndGoodsBrand> page = new Page<GoodsAndShopAndGoodsTypeAndGoodsBrand>();
//        得到记录总数
        Integer pageToTalCount = adminMapper.getGoodsToBePutOnSaleCount();
        page.setPageTotalCount(pageToTalCount);
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        int star = (pageNow - 1) * pageSize;
        page.setStart(star);
        ArrayList<GoodsAndShopAndGoodsTypeAndGoodsBrand> list = adminMapper.selectGoodsToBePutOnSaleByPage(page.getStart(), page.getPageSize());
        page.setList(list);
        return page;
    }

    @Override
    public Page<GoodsAndShopAndGoodsTypeAndGoodsBrand> likeGoodsToBePutOnSaleByPage(int pageNow, int pageSize, String goodsName) {
        Page<GoodsAndShopAndGoodsTypeAndGoodsBrand> page = new Page<GoodsAndShopAndGoodsTypeAndGoodsBrand>();
//        得到记录总数
        Integer pageToTalCount = adminMapper.getGoodsToBePutOnSaleCount();
        page.setPageTotalCount(pageToTalCount);
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        int star = (pageNow - 1) * pageSize;
        page.setStart(star);
        ArrayList<GoodsAndShopAndGoodsTypeAndGoodsBrand> list = adminMapper.likeGoodsToBePutOnSaleByPage(page.getStart(), page.getPageSize(), goodsName);
        page.setList(list);
        return page;
    }

    /**
     *与判断有关的
     */


    @Override
    public int checkNicknameIsSingle(String nickName) {
        logger.info(nickName);
        return adminMapper.checkNicknameIsSingle(nickName);
    }

    @Override
    public int checkTelephoneIsSingle(String telephone) {
        return adminMapper.checkTelephoneIsSingle(telephone);
    }

    @Override
    public int checkEmailIsSingle(String email) {
        return adminMapper.checkEmailIsSingle(email);
    }

    /**
     *判断昵称、手机号、邮箱、银行卡号存在
     */
    public Boolean checkNicknameIsPresent(String nickname){
        int row =checkNicknameIsSingle(nickname);
        if (row!=0){
            return true;
        }
        else{
            return false;
        }
    }
    public Boolean checkTelephoneIsPresent(String telephone){
        int rows = checkTelephoneIsSingle(telephone);
        if (rows!=0){
            return true;
        }
        else {
            return false;
        }
    }
    public Boolean checkEmailIsPresent(String email){
        int rows = checkEmailIsSingle(email);
        if (rows!=0){
            return true;
        }
        else {
            return false;
        }
    }



    /**
     * 判断插入返回的信息
     *
     * @Return message
     */
    public String getTheInsertUserMessage(String nickname, String sex, @RequestParam(defaultValue="0")int age, String password, String telephone, String email, String address, String idCard, String rName) {
//            判断昵称是否存在
             Boolean nicknameTruOrFalse=checkNicknameIsPresent(nickname);
//             判断手机号是否存在
             Boolean telephoneTrueOrFalse=checkTelephoneIsPresent(telephone);
//             判断邮箱是否存在
             Boolean emailTrueOrFalse=checkEmailIsPresent(email);
//             检查手机号格式
             Boolean telephoneIsLegalOrNo=adminUtils.checkTelephoneIsIllegal(telephone);
//             检查邮箱格式是否正确
             Boolean emailIsLegalOrNo=adminUtils.checkEmailIsIllegal(email);
        if (nickname == null || nickname.equals("")) { return "输入昵称为空或“ ”"; }
        else if (nickname.length() > 6) { return "输入昵称超出最大长度"; }
//        if (nicknameTruOrFalse){return "输入昵称已存在";}
//        if (sex==null||sex.equals(" ")){return "输入性别为空或为“ ”"; }
        else if (!sex.equals("男")&&!sex.equals("女")) { return "输入的性别不合法"; }
        else if(String.valueOf(age)!=null){
            if (age > 100||age<0) { return "输入年龄超出规定范围"; }
        }
        else if (password==null||password.equals(" ")){return "输入密码为空或为“ ”"; }
        else if (password.length() <6||password.length()>16) { return "输入密码超出规定范围"; }
        else if(telephone!=null){
            if (telephoneTrueOrFalse) { return "输入手机号已存在"; }
            if (telephoneIsLegalOrNo){return "输入手机号非法定格式"; }
        }
//        if (telephone==null||telephone.equals(" ")){return "输入手机号为空或为“ ”"; }
//        if (telephoneTrueOrFalse) { return "输入手机号已存在"; }
        else if (telephoneIsLegalOrNo){return "输入手机号非法定格式"; }
        else if (email == null || email.equals("")) { return "输入邮箱为空或“ ”"; }
//        if (emailTrueOrFalse) { return "输入邮箱已经存在"; }
//        if (emailIsLegalOrNo){return "输入邮箱非法定格式"; }
//        if (address == null || address.equals("")) { return "输入地址为空或“ ”"; }
        else if(address!=null){
            if (address.length() < 6||address.length()>50) { return "输入地址超出规定长度长度"; }

        }
        else if(idCard!=null){
            if (idCard.length()!=16) { return "输入银行卡号不符合规定"; }

        }
//        if (idCard == null || idCard.equals("")) { return "输入银行卡号为空或“ ”"; }
        else if(rName!=null){
//            if (rName == null || rName.equals("")) { return "输入真实姓名为空或“ ”"; }
            if (rName.length() < 2||rName.length()>6) { return "输入真实姓名超出规定长度长度"; }
        }

        int rows=adminMapper.adminAddUser(nickname,sex,age,password,telephone,email,address,idCard,rName);
        return "修改成功";
    }
    /**
     * 判断修改返回的信息
     *
     * @Return message
     */
    public String getTheUpdateUserMessage(int userId, String nickname, String sex, String telephone, String rName) {

        if (nickname == null || nickname.equals("")) { return "输入昵称为空或“ ”"; }
        else if (nickname.length() > 6) { return "输入昵称超出最大长度"; }
        else if(sex!=null){
            if (!sex.equals("男")&&!sex.equals("女")) { return "输入的性别不合法"; }
        }

        else if(telephone!=null){
            if(!teleNumUtils.TelephoneBool(telephone)){
                logger.info("手机号不合法");
            }
        }
        else if(rName!=null) {
            if (rName.length() < 2 || rName.length() > 6) {
                return "输入真实姓名超出规定长度长度";
            }
        }

            int rows=adminMapper.adminUpdateUser(userId,nickname,sex,telephone,rName);
            return "修改成功";

}
    /**
     * 判断插入返回的信息
     *
     * @Return message
     */
    public String getTheInsertShopperMessage(String nickname, String sex, @RequestParam(defaultValue="0")int age, String password, String telephone, String email, String address, String idCard, String rName) {
//            判断昵称是否存在
        Boolean nicknameTruOrFalse=checkNicknameIsPresent(nickname);
//             判断手机号是否存在
        Boolean telephoneTrueOrFalse=checkTelephoneIsPresent(telephone);
//             判断邮箱是否存在
        Boolean emailTrueOrFalse=checkEmailIsPresent(email);
//             检查手机号格式
        Boolean telephoneIsLegalOrNo=adminUtils.checkTelephoneIsIllegal(telephone);
//             检查邮箱格式是否正确
        Boolean emailIsLegalOrNo=adminUtils.checkEmailIsIllegal(email);
        if (nickname == null || nickname.equals("")) { return "输入昵称为空或“ ”"; }
        if (nickname.length() > 6) { return "输入昵称超出最大长度"; }
        if (nicknameTruOrFalse){return "输入昵称已存在";}
        if (sex==null||sex.equals(" ")){return "输入性别为空或为“ ”"; }
        if (!sex.equals("男")&&!sex.equals("女")) { return "输入的性别不合法"; }
        if (age > 100||age<0) { return "输入年龄超出规定范围"; }
        if (password==null||password.equals(" ")){return "输入密码为空或为“ ”"; }
        if (password.length() <6||password.length()>16) { return "输入密码超出规定范围"; }
        if (telephone==null||telephone.equals(" ")){return "输入手机号为空或为“ ”"; }
        if (telephoneTrueOrFalse) { return "输入手机号已存在"; }
        if (telephoneIsLegalOrNo){return "输入手机号非法定格式"; }
        if (email == null || email.equals("")) { return "输入邮箱为空或“ ”"; }
        if (emailTrueOrFalse) { return "输入邮箱已经存在"; }
        if (emailIsLegalOrNo){return "输入邮箱非法定格式"; }
        if (address == null || address.equals("")) { return "输入地址为空或“ ”"; }
        if (address.length() < 6||address.length()>50) { return "输入地址超出规定长度长度"; }
        if (idCard == null || idCard.equals("")) { return "输入银行卡号为空或“ ”"; }
        if (idCard.length()!=16) { return "输入银行卡号不符合规定"; }
        if (rName == null || rName.equals("")) { return "输入真实姓名为空或“ ”"; }
        if (rName.length() < 2||rName.length()>6) { return "输入真实姓名超出规定长度长度"; }
        else {
            int rows=adminMapper.adminAddShopper(nickname,sex,age,password,telephone,email,address,idCard,rName); return "添加成功"; }
    }
    /**
     * 判断修改返回的信息
     *
     * @Return message
     */
    public String getTheUpdateShopperMessage(int userId, String nickname, String sex, @RequestParam(defaultValue="0")int age, String password, String telephone, String email, String address, String idCard, String rName) {
//            判断昵称是否存在
        Boolean nicknameTruOrFalse=checkNicknameIsPresent(nickname);
//             判断手机号是否存在
        Boolean telephoneTrueOrFalse=checkTelephoneIsPresent(telephone);
//             判断邮箱是否存在
        Boolean emailTrueOrFalse=checkEmailIsPresent(email);
//             检查手机号格式
        Boolean telephoneIsLegalOrNo=adminUtils.checkTelephoneIsIllegal(telephone);
//             检查邮箱格式是否正确
        Boolean emailIsLegalOrNo=adminUtils.checkEmailIsIllegal(email);
        if (nickname == null || nickname.equals("")) { return "修改昵称为空或“ ”"; }
        if (nickname.length() > 6) { return "修改昵称超出最大长度"; }
        if (nicknameTruOrFalse){return "修改昵称已存在";}
        if (sex==null||sex.equals(" ")){return "修改性别为空或为“ ”"; }
        if (!sex.equals("男")&&!sex.equals("女")) { return "修改的性别不合法"; }
        if (age > 100||age<0) { return "修改年龄超出规定范围"; }
        if (password==null||password.equals(" ")){return "修改密码为空或为“ ”"; }
        if (password.length() <6||password.length()>16) { return "修改密码超出规定范围"; }
        if (telephone==null||telephone.equals(" ")){return "修改手机号为空或为“ ”"; }
        if (telephoneTrueOrFalse) { return "修改手机号已存在"; }
        if (telephoneIsLegalOrNo){return "修改手机号非法定格式"; }
        if (email == null || email.equals("")) { return "修改邮箱为空或“ ”"; }
        if (emailTrueOrFalse) { return "修改邮箱已经存在"; }
        if (emailIsLegalOrNo){return "修改邮箱非法定格式"; }
        if (address == null || address.equals("")) { return "修改地址为空或“ ”"; }
        if (address.length() < 6||address.length()>50) { return "修改地址超出规定长度长度"; }
        if (idCard == null || idCard.equals("")) { return "修改银行卡号为空或“ ”"; }
        if (idCard.length()!=16) { return "修改银行卡号不符合规定"; }
        if (rName == null || rName.equals("")) { return "修改真实姓名为空或“ ”"; }
        if (rName.length() < 2||rName.length()>6) { return "修改真实姓名超出规定长度长度"; }
        else {
            int rows=adminMapper.adminUpdateShopper(userId,nickname,sex,age,password,telephone,email,address,idCard,rName); return "修改成功"; }

    }

    /**
     * 判断删除对象是否存在
     */
    @Override
    public int checkUserIdIsPresent(int userId) {
       int row =adminMapper.cheUserIdIsPresent(userId);
       return row;
    }

    @Override
    public int checkShopIdIsPresent(int shopId) {
        int row =adminMapper.checkShopIdIsPresent(shopId);
        return row;
    }

    @Override
    public int checkGoodsIdIsPresent(int goodsId) {
        int row =adminMapper.checkGoodsIdIsPresent(goodsId);
        return row;
    }

    /**
     *批量删除操作
     */
//    @Override
//    public int deleteManyUser(Integer[] userIds) {
//        return adminMapper.deleteManyUser(userIds);
//    }

}



//        if (" ".equals(password)||" ".equals(nickname)||" ".equals(telephone)||" ".equals(email)||" ".equals(address)||" ".equals(idCard)||" ".equals(rName)){
//            return rows;
//        }else if (password==null||nickname==null||telephone==null||email==null||address==null||idCard==null||rName==null){
//            rows=1;
//            return rows;
//        }else{
//            if (adminUtils.checkNicknameIsPresent(nickname)){
//                rows =2;
//                return rows;
//            }else if (adminUtils.checkTelephoneIsPresent(telephone)){
//                rows =3;
//                return rows;
//            }else if (adminUtils.checkEmailIsPresent(email)){
//                rows = 4;
//                return rows;
//            }else {
//                if (adminUtils.checkTelephoneIsIllegal(telephone)){
//                    rows = 5;
//                    return rows;
//                }else if (adminUtils.checkEmailIsIllegal(email)){
//                    rows=6;
//                    return rows;
//                }else {
//                    if (nickname.length()>7){
//                        rows=7;
//                        return rows;
//                    }else if (!"男".equals(sex)||!"女".equals(sex)){
//                        rows=8;
//                        return rows;
//                    }else if (age<1||age>100){
//                        rows=9;
//                        return rows;
//                    }else if (password.length()<6||password.length()>16){
//                        rows=10;
//                        return rows;
//                    }else if (address.length()<6||address.length()>50){
//                        rows =11;
//                        return rows;
//                    }else if (idCard.length()!=16){
//                        rows=12;
//                        return rows;
//                    }else if (rName.length()>6||rName.length()<2){
//                        rows=13;
//                        return rows;
//                    }else {
//                         int line=adminMapper.adminAddUser(nickname,sex,age,password,telephone,email,address,idCard,rName);
//                        rows=200;
//                         return rows;
//                    }
//                }
//            }
//        }
//
//    }




